import { createSlice } from "@reduxjs/toolkit";

const CounterSlice = createSlice({
    name: 'counter',
    initialState: {
        count: 0,
        data: <Data[]>[]
    },
    reducers: {
        increment(state) {
            state.count++
        },
        decrement(state) {
            state.count--
        },
        updateData(state, action) {
            state.data = action.payload
        }
    }
})

const fetchData = () => {
    return async (dispatch) => {
        const data = [{pos: 1, len: 3}]
        dispatch(updateData(data))
    }
}

export const { increment, decrement, updateData } = CounterSlice.actions

export { fetchData }

export default CounterSlice.reducer